import Vue from "vue";
import Vuex from "vuex";
import classfication from "../modules/ClassficationModule/store.js";
import program_type from "../modules/ProgramTypeModule/store.js";
import movie_wall from "../modules/MovieWallModule/store.js";

import types from "./mutation-types.js";
import Filter from "./filter.js";
import app from "../../app.config.js";
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    // 默认数据为初始化
    params: {
      last_note_id: 0,
      last_note_value: "", //最后一条数据的值
      program_type: "0",
      type: "",
      time: "",
      area: "",
      welcome: "play",
      num: app.request_num
    }
  },
  mutations: {
    [types.UPDATE_LAST_NOTE_ID](state, new_val) {
      state.params.last_note_id = new_val;
    },
    [types.UPDATE_LAST_NOTE_VALUE](state, last_note) {
      let new_val = "";
      if (last_note === null) {
        new_val = "";
      } else {
        new_val = last_note[state.params.welcome];
      }
      state.params.last_note_value = new_val;
    },
    [types.UPDATE_PARAMS_VALUE](state, { key, value }) {
      state.params[key] = Filter(key, value);
      this.dispatch("movie_wall/updateMovieWallDatas");
    }
  },
  actions: {},
  modules: {
    classfication,
    program_type,
    movie_wall
  }
});
